import { NestFactory } from '@nestjs/core';
import { ValidationPipe } from '@nestjs/common';

import { AppModule } from './app.module';
import { LoggerMiddleware } from './middlewares/logger.middleware';
import { AuthGuard } from './guards/auth.guard';
import { ResponseInterceptor } from './interceptors/response.interceptor';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  // 1.中间件
  // 全局使用(注意后面的 use)
  app.use(new LoggerMiddleware().use);

  // 2.守卫
  app.useGlobalGuards(new AuthGuard());

  // 3.拦截器
  app.useGlobalInterceptors(new ResponseInterceptor());

  // 4.管道(参数校验)
  app.useGlobalPipes(new ValidationPipe());

  await app.listen(3000);
}

bootstrap();
